<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!--    var str = '111 222 333';
            要求用js实现去除中间的空格 -->

    <script> 
              let str = '  111 222 333   ';
        //    //正则+replace
        //    let reg=/\s/g

        //    console.log(str.replace(reg,''))

           //数组api的filter
           let strList =str.split('')

           let result=strList.filter(item=>{
               return item !==' '
           })

           console.log(result.join(''))
    </script>
</body>
</html>